﻿//
// XN4SL - Xna Framework for Silverlight.
//
using System;

namespace Xn4Sl.Framework
{
    /// <summary>
    /// Defines a point in 2D space.
    /// </summary>
    public struct Point : IEquatable<Point>
    {
        /// <summary>
        /// Specifies the x-coordinate of the Point.
        /// </summary>
        private int x;
        public int X
        {
            get
            {
                return this.x;
            }
            set
            {
                this.x = value;
            }
        }

        /// <summary>
        /// Specifies the y-coordinate of the Point.
        /// </summary>
        private int y;
        public int Y
        {
            get
            {
                return this.y;
            }
            set
            {
                this.y = value;
            }
        }

        /// <summary>
        /// Initializes a new instance of Point.
        /// </summary>
        /// <param name="x">The x-coordinate of the Point.</param>
        /// <param name="y">The y-coordinate of the Point.</param>
        public Point(int x, int y)
        {
            this.x = x;
            this.y = y;
        }

        /// <summary>
        /// Determines whether two Point instances are not equal.
        /// </summary>
        /// <param name="a">The Point on the left side of the equal sign.</param>
        /// <param name="b">The Point on the right side of the equal sign.</param>
        /// <returns>true if the instances are not equal; false otherwise.</returns>
        public static bool operator !=(Point a, Point b)
        {
            return !(a == b);
        }

        /// <summary>
        /// Determines whether two Point instances are equal.
        /// </summary>
        /// <param name="a">Point on the left side of the equal sign.</param>
        /// <param name="b">Point on the right side of the equal sign.</param>
        /// <returns>true if a and bare equal; false otherwise.</returns>
        public static bool operator ==(Point a, Point b)
        {
            return a.Equals(b);
        }

        /// <summary>
        /// Returns the point (0,0).
        /// </summary>
        public static Point Zero 
        {
            get
            {
                return new Point(0, 0);
            }
        }

        /// <summary>
        /// Determines whether two Point instances are equal.
        /// </summary>
        /// <param name="obj">The object to compare this instance to.</param>
        /// <returns>true if the instances are equal; false otherwise.</returns>
        public override bool Equals(object obj)
        {
            return this.GetHashCode() == obj.GetHashCode();
        }
    
        /// <summary>
        /// Determines whether two Point instances are equal.
        /// </summary>
        /// <param name="other">The Point to compare this instance to.</param>
        /// <returns>true if the instances are equal; false otherwise.</returns>
        public bool Equals(Point other)
        {
            return this.GetHashCode() == other.GetHashCode();
        }
  
        /// <summary>
        /// Gets the hash code for this object.
        /// </summary>
        /// <returns>The hash code for this object.</returns>
        public override int GetHashCode()
        {
            return this.X.GetHashCode() ^ this.Y.GetHashCode();
        }

        /// <summary>
        /// Returns a System.String that represents the current Point.
        /// </summary>
        /// <returns>A System.String that represents the current Point.</returns>
        public override string ToString()
        {
            return String.Format("{{X:{0} Y:{1}{2}", this.X, this.Y, "}");
        }
    }
}
